package com.example.easydownloadback.controller;

import com.example.easydownloadback.domin.LoginFormDTO;
import com.example.easydownloadback.domin.PasswordFormDTO;
import com.example.easydownloadback.domin.ResponseResult;
import com.example.easydownloadback.domin.UserDTO;
import com.example.easydownloadback.service.UserService;
import com.example.easydownloadback.util.Code;
import com.example.easydownloadback.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 登录功能
     * @param loginForm 登录参数，包含账号、密码
     */
    @PostMapping("/login")
    public ResponseResult<String> login(@RequestBody LoginFormDTO loginForm){
        // 实现登录功能
        return userService.login(loginForm);
    }
    /**
     * 获取当前登录用户并返回
     */
    @GetMapping("/me")
    public ResponseResult<UserDTO> me() {
        UserDTO user = UserHolder.getUser();
        return new ResponseResult<>(Code.success, user);
    }
    @PostMapping("/password")
    public ResponseResult password(@RequestBody PasswordFormDTO passwordFormDTO) {
        return userService.password(passwordFormDTO);
    }

}
